package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.*;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class AddMovie extends InternalPage {

	public AddMovie(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "name")
	private WebElement titleField;
	
	@FindBy(name = "year")
	private WebElement yearField;
	
	@FindBy(name = "submit")
	private WebElement submitButton;
	
	
	public AddMovie setTitleField(String text) {
		titleField.sendKeys(text);
		return this;
	}
	
	public AddMovie setYearField(String text) {
		yearField.sendKeys(text);
		return this;
	}
	
	public void clickSubmitButton() {
		submitButton.click();
	}
	
	public boolean fieldIsWrong(){
		if (driver.findElement(By.cssSelector(".error")).isDisplayed()){
			System.out.println("fieldIsWrong = true");
			return true;
		} else{
			System.out.println("fieldIsWrong = true");
			return false;
		}
	}
	
	public AddMovie fieldHaveWrongText(){
		wait.until(presenceOfElementLocated(By.cssSelector(".error")));
		return this;
	}
	
	public AddMovie ensurePageLoaded() {
 		super.ensurePageLoaded();
 		wait.until(presenceOfElementLocated(By.cssSelector(".addmovie")));
 		return this;
 	}
	
	
	

}
